package io.github.wppli.domain.posts.event;


import io.github.wppli.domain.posts.model.valobj.UserPostsBehaviorType;
import io.github.wppli.types.event.BaseEvent;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * 计算帖子TF-IDF事件
 * @author li--jiaqiang 2025−03−16
 */
@Component
public class CalculatePostsTfIdfEvent extends BaseEvent<CalculatePostsTfIdfEvent.CalculatePostsTfIdfMessage> {

    @Value("${spring.rabbitmq.topic.calculatePostsTFIDF}")
    private String topic;

    @Override
    public EventMessage<CalculatePostsTfIdfMessage> buildEventMessage(CalculatePostsTfIdfMessage data) {
        return EventMessage.<CalculatePostsTfIdfEvent.CalculatePostsTfIdfMessage>builder()
                .id(String.valueOf(snowflakeIdGenerator.nextId()))
                .timestamp(new Date())
                .data(data)
                .build();
    }

    @Override
    public String topic() {
        return topic;
    }

    @Data
    @Builder
    @AllArgsConstructor
    @NoArgsConstructor
    public static class CalculatePostsTfIdfMessage {
        /**
         * 用户ID
         */
        private Long userId;
        /**
         * 帖子ID
         */
        private Long contentId;

        /**
         * 帖子正文
         */
        private String content;

        /**
         * 用户行为
         */
        private UserPostsBehaviorType userPostsBehaviorType;
    }
}